package com.captainbank.tcl.tclapplication.utils;

import com.captainbank.tcl.tclapplication.model.TestBean;
import com.google.gson.Gson;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by TCL on 2019/2/15.
 * Describe:
 */
public class NetTools {
    /**
     * 不带token的网络请求：
     * 原文 -> AES(AES / CBC/ No Padding) -> base64 -> 密文
     * @param mMap：参数集合
     * @return  encryptionString: 加密后的json字符串
     */
    public static String getEncryptionString(HashMap<String, Object> mMap) {
        Gson gson = new Gson();
        String mapString = gson.toJson(mMap);
        String aess = AESUtils.encryptData(mapString);
        HashMap<String, String> map = new HashMap<>();
        map.put("code", aess);
        String s2 = gson.toJson(map);
        String encryptionString = s2.replace("\\n", "");
        return encryptionString;
    }

    public static TestBean getEncryptionBean(HashMap<String, Object> mMap) {
        Gson gson = new Gson();
        String mapString = gson.toJson(mMap);
        String aess = AESUtils.encryptData(mapString);
        TestBean tb = new TestBean();
        tb.setCode(aess);
        return  tb;
    }

    public static RequestBody getEncryptionRequestBody(HashMap<String, Object> mMap) {
        Gson gson = new Gson();
        String mapString = gson.toJson(mMap);
        String aess = AESUtils.encryptData(mapString);
        HashMap<String, String> map = new HashMap<>();
        map.put("code", aess);
        String s2 = gson.toJson(map);
        String encryptionString = s2.replace("\\n", "");
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"),encryptionString);
        return  requestBody;
    }




    /**
     * 带token的网络请求：
     * @param mMap：参数集合
     * @return  parameterString: json字符串
     */
    public static String getParameterString(HashMap<String, Object> mMap) {
        Gson gson = new Gson();
        String mapString = gson.toJson(mMap);
        String parameterString = mapString.replace("\\n", "");
        return parameterString;
    }

//    public static String getToken(Activity context) {
//        MyApplication myApplication = (MyApplication) context.getApplication();
//        String token = myApplication.getToken();
//        if(StringUtil.checkIsNotNull(token)){
//            return token;
//        }else{
//            return "";
//        }
//
//    }

//    public static Object getModel(LzyResponse mLzyResponse) {
//        return mLzyResponse.result;
//    }

}
